import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';

@Component({
  selector: 'app-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.css']
})
export class UploadComponent implements OnInit {
  selectedFile:string;
  constructor(private http:HttpClient) { }

  ngOnInit() {
  }


  onFileChanged(event) {
    this.selectedFile = event.target.files[0];
    //this.onUpload();
  }


  onUpload() {
    // upload code goes here

    const uploadData = new FormData();
  uploadData.append('file', this.selectedFile);
  this.http.post('http://localhost/manage/fileUpload',uploadData).subscribe(
    (data:any)=>{
     // alert(data);
      console.log(JSON.stringify(data));
    },(err:HttpErrorResponse)=>{
      console.log(err.message);
    }
  )

  }
}
